home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0057_Clear All attributes on Files.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  4.4 KB  |  167 lines

  1. program Delattr;
  2.  
  3. Uses Dos;
  4.  
  5.  
  6. Procedure Usage;
  7. Begin
  8.      Writeln;
  9.      Writeln('DELATTR (C) 1995 Scott Tunstall.');
  10.      Writeln('Gets rid of those annoying undeletable files quickly !');
  11.      Writeln;
  12.      Writeln;
  13.      Writeln('Usage:');
  14.      Writeln;
  15.      Writeln('DELATTR [-r] [-s] [-a] [-h] <FileSpec>');
  16.      Writeln;
  17.      Writeln('   -r will remove the READ ONLY attribute of a file,');
  18.      Writeln('   -s will remove the SYSTEM attribute,');
  19.      Writeln('   -a will remove the ARCHIVE attribute,');
  20.      Writeln('   -h will remove the HIDDEN attribute.');
  21.      Writeln;
  22.      Writeln;
  23.      Writeln('If you do not specify any attribute parameters, the');
  24.      Writeln('program assumes you want to remove ALL of the');
  25.      Writeln('specified file''s attributes. Or Something. :-) ');
  26.      Writeln;
  27.      Writeln('Use ATTRIB if all you want to do is ADD or VIEW ');
  28.      Writeln('the attributes of file(s).');
  29.      Writeln;
  30. End;
  31.  
  32.  
  33. Procedure BreakDownMask(TheMask: Word);
  34. Begin
  35.      If TheMask <>0 Then
  36.         Begin
  37.         If TheMask AND Archive = Archive Then
  38.            Write('A ');
  39.         If TheMask AND Directory = Directory Then
  40.            Write('D ');
  41.         If TheMask AND Hidden = Hidden Then
  42.            Write('H ');
  43.         If TheMask AND ReadOnly = ReadOnly Then
  44.            Write('R ');
  45.         If TheMask AND SysFile = SysFile Then
  46.            Write('S ');
  47.         If TheMask AND VolumeID = VolumeID Then
  48.            Write('V ');
  49.         End
  50.      Else
  51.          Write('NULL ');
  52. End;
  53.  
  54.  
  55. {
  56. ReadOnly     │  $01
  57. Hidden       │  $02
  58. SysFile      │  $04
  59. VolumeID     │  $08
  60. Directory    │  $10
  61. Archive      │  $20
  62. AnyFile      │  $3F
  63. }
  64.  
  65. Procedure DoAttrib;
  66. Var Count: Byte;
  67.     FileToChange: File;
  68.     TempParam: string;
  69.     CurrentByteMask: Word;
  70.     ByteMask : Word;
  71.     SearchRc: SearchRec;
  72.  
  73. Begin
  74.      ByteMask:=0;
  75.      If ParamCount = 1 Then
  76.         ByteMask:=$2f
  77.      Else
  78.          For Count:=1 to (ParamCount -1) do
  79.              Begin
  80.              TempParam:=ParamStr(Count);
  81.              If TempParam[1] = '-' Then
  82.              Begin
  83.                 Case upcase(TempParam[2]) of
  84.                 'A': ByteMask:=ByteMask OR Archive;
  85.                 'D': ByteMask:=ByteMask OR Directory;
  86.                 'H': ByteMask:=ByteMask OR Hidden;
  87.                 'R': ByteMask:=ByteMask OR ReadOnly;
  88.                 'S': ByteMask:=ByteMask OR SysFile;
  89.                 'V': ByteMasK:=ByteMask OR VolumeID;
  90.                 Else
  91.                     Begin
  92.                     Write(chr(7));
  93.                     Writeln(Paramstr(Count),' is not a valid switch !');
  94.                     Halt;
  95.                     End
  96.                 End;
  97.                 End
  98.              Else
  99.                  Begin
  100.                  Write(chr(7));
  101.                  Writeln(ParamStr(Count),' is not recognised as a switch !');
  102.                  Halt;
  103.                  End;
  104.          End;
  105.  
  106.      FindFirst(ParamStr(ParamCount),AnyFile, SearchRc);
  107.      If DosError =0 Then
  108.         Begin
  109.         While DosError = 0 do
  110.               Begin
  111.               Assign(FileToChange,SearchRc.Name);
  112.               GetFAttr(FileToChange,CurrentByteMask);
  113.  
  114.               If CurrentByteMask <>0 Then
  115.                  Begin
  116.  
  117.                  CurrentByteMask:=CurrentByteMask AND (65535 - ByteMask);
  118.                  If ByteMask <>$2f Then
  119.                     Begin
  120.                     Write('Changed attributes of ',SearchRc.Name,' to ');
  121.                     BreakDownMask(CurrentByteMask);
  122.                     End
  123.                  Else
  124.                      Write('Removed all attributes from ',SearchRc.Name);
  125.  
  126.                  SetFAttr(FileToChange,CurrentByteMask);
  127.  
  128.                  If DosError = 0 Then
  129.                     Write(' [OK].')
  130.                  Else
  131.                      Write('[Access Denied]');
  132.  
  133.                  Writeln;
  134.  
  135.                  FindNext(SearchRc);
  136.                  End
  137.               Else
  138.                   Begin
  139.                   Writeln(SearchRc.Name, ' has no file attributes [OK].');
  140.                   FindNext(SearchRc);
  141.               End;
  142.         End;
  143.  
  144.         Writeln;
  145.         Writeln('Operation complete.');
  146.         Writeln;
  147.  
  148.         End
  149.      Else
  150.          Begin
  151.          Writeln('Could not find the specified file(s) !');
  152.          Writeln;
  153.          End;
  154. End;
  155.  
  156.  
  157.  
  158.  
  159.  
  160. Begin
  161.      If ParamCount = 0 Then
  162.         Usage
  163.      Else
  164.          Doattrib;
  165. End.
  166.  
  167.